package com.proxy.daijia.driver.service.impl;

import com.proxy.daijia.common.execption.ProxyException;
import com.proxy.daijia.common.result.ResultCodeEnum;
import com.proxy.daijia.driver.client.DriverInfoFeignClient;
import com.proxy.daijia.driver.service.LocationService;
import com.proxy.daijia.map.client.LocationFeignClient;
import com.proxy.daijia.model.entity.driver.DriverSet;
import com.proxy.daijia.model.form.map.UpdateDriverLocationForm;
import com.proxy.daijia.model.form.map.UpdateOrderLocationForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class LocationServiceImpl implements LocationService {

    @Autowired
    private LocationFeignClient locationFeignClient;

    @Autowired
    private DriverInfoFeignClient driverInfoFeignClient;

    //开启接单服务：更新司机经纬度位置
    @Override
    public Boolean updateDriverLocation(UpdateDriverLocationForm updateDriverLocationForm) {
        //获取司机的个性化信息
        DriverSet driverSet = driverInfoFeignClient.getDriverSet(updateDriverLocationForm.getDriverId()).getData();
        //判断司机是否开始接单
        if (driverSet.getServiceStatus().intValue() == 1) {
            return locationFeignClient.updateDriverLocation(updateDriverLocationForm).getData();
        }else {
            throw  new ProxyException(ResultCodeEnum.NO_START_SERVICE);
        }
    }

    //司机赶往代驾起始点：更新订单位置到Redis缓存
    @Override
    public Object updateOrderLocationToCache(UpdateOrderLocationForm updateOrderLocationForm) {
        return locationFeignClient.updateOrderLocationToCache(updateOrderLocationForm).getData();
    }
}
